// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using System;
using System.Linq;
using Elastic.Clients.Elasticsearch.Serialization;

namespace Elastic.Clients.Elasticsearch.Xpack.Json;

public sealed partial class EqlFeaturesJoinConverter : System.Text.Json.Serialization.JsonConverter<Elastic.Clients.Elasticsearch.Xpack.EqlFeaturesJoin>
{
	private static readonly System.Text.Json.JsonEncodedText PropJoinQueriesFiveOrMore = System.Text.Json.JsonEncodedText.Encode("join_queries_five_or_more");
	private static readonly System.Text.Json.JsonEncodedText PropJoinQueriesFour = System.Text.Json.JsonEncodedText.Encode("join_queries_four");
	private static readonly System.Text.Json.JsonEncodedText PropJoinQueriesThree = System.Text.Json.JsonEncodedText.Encode("join_queries_three");
	private static readonly System.Text.Json.JsonEncodedText PropJoinQueriesTwo = System.Text.Json.JsonEncodedText.Encode("join_queries_two");
	private static readonly System.Text.Json.JsonEncodedText PropJoinUntil = System.Text.Json.JsonEncodedText.Encode("join_until");

	public override Elastic.Clients.Elasticsearch.Xpack.EqlFeaturesJoin Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
	{
		reader.ValidateToken(System.Text.Json.JsonTokenType.StartObject);
		LocalJsonValue<int> propJoinQueriesFiveOrMore = default;
		LocalJsonValue<int> propJoinQueriesFour = default;
		LocalJsonValue<int> propJoinQueriesThree = default;
		LocalJsonValue<int> propJoinQueriesTwo = default;
		LocalJsonValue<int> propJoinUntil = default;
		while (reader.Read() && reader.TokenType is System.Text.Json.JsonTokenType.PropertyName)
		{
			if (propJoinQueriesFiveOrMore.TryReadProperty(ref reader, options, PropJoinQueriesFiveOrMore, null))
			{
				continue;
			}

			if (propJoinQueriesFour.TryReadProperty(ref reader, options, PropJoinQueriesFour, null))
			{
				continue;
			}

			if (propJoinQueriesThree.TryReadProperty(ref reader, options, PropJoinQueriesThree, null))
			{
				continue;
			}

			if (propJoinQueriesTwo.TryReadProperty(ref reader, options, PropJoinQueriesTwo, null))
			{
				continue;
			}

			if (propJoinUntil.TryReadProperty(ref reader, options, PropJoinUntil, null))
			{
				continue;
			}

			if (options.UnmappedMemberHandling is System.Text.Json.Serialization.JsonUnmappedMemberHandling.Skip)
			{
				reader.SafeSkip();
				continue;
			}

			throw new System.Text.Json.JsonException($"Unknown JSON property '{reader.GetString()}' for type '{typeToConvert.Name}'.");
		}

		reader.ValidateToken(System.Text.Json.JsonTokenType.EndObject);
		return new Elastic.Clients.Elasticsearch.Xpack.EqlFeaturesJoin(Elastic.Clients.Elasticsearch.Serialization.JsonConstructorSentinel.Instance)
		{
			JoinQueriesFiveOrMore = propJoinQueriesFiveOrMore.Value,
			JoinQueriesFour = propJoinQueriesFour.Value,
			JoinQueriesThree = propJoinQueriesThree.Value,
			JoinQueriesTwo = propJoinQueriesTwo.Value,
			JoinUntil = propJoinUntil.Value
		};
	}

	public override void Write(System.Text.Json.Utf8JsonWriter writer, Elastic.Clients.Elasticsearch.Xpack.EqlFeaturesJoin value, System.Text.Json.JsonSerializerOptions options)
	{
		writer.WriteStartObject();
		writer.WriteProperty(options, PropJoinQueriesFiveOrMore, value.JoinQueriesFiveOrMore, null, null);
		writer.WriteProperty(options, PropJoinQueriesFour, value.JoinQueriesFour, null, null);
		writer.WriteProperty(options, PropJoinQueriesThree, value.JoinQueriesThree, null, null);
		writer.WriteProperty(options, PropJoinQueriesTwo, value.JoinQueriesTwo, null, null);
		writer.WriteProperty(options, PropJoinUntil, value.JoinUntil, null, null);
		writer.WriteEndObject();
	}
}